<?php

// +----------------------------------------------------------------------
// | 版权所有 2017-2027 云南环拓科技有限公司，并保留所有权利。
// +----------------------------------------------------------------------
// | Copyright (c) 2017-2027 http://www.yn123.com All rights reserved.
// +----------------------------------------------------------------------
// | Notice: This code is not open source, it is strictly prohibited
// |         to distribute the copy, otherwise it will pursue its
// |         legal responsibility.
// | 注意：  这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用,
// |        不允许对程序代码以任何形式任何目的的再发布。
// +----------------------------------------------------------------------
// | Author: feraner <feraner@163.com> 
// | Date: 2019/12/9
// +----------------------------------------------------------------------

namespace app\index\controller\api;

use app\common\services\AdvertService;
use think\App;
use think\Db;

/**
 * 首页接口
 * Class HomePage
 * @package app\index\controller\api
 * @author feraner<feraner@163.com>
 * @date 2019/12/9
 */
class HomePage extends ApiBase
{

    public function __construct(App $app = null)
    {
        parent::__construct($app);
    }


    /**
     * 首页
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function index()
    {

        //首页轮播广告
        $swipeList = (new AdvertService())->getAdvertList(1);

        //公告
        $publicNotice = Db::name('web_news')->alias('wn')
            ->join('web_news_type wnt', 'wn.tid = wnt.id')
            ->where('wnt.flag', 'system_notice')
            ->where('wn.status', 1)
            ->order('wn.sort', 'ASC')
            ->field('wn.*')
            ->find() ?: [];

        //首页广告列表
        $advList = [
            'adv1'  => (new AdvertService())->getAdvertList(5),
            'adv2'  => (new AdvertService())->getAdvertList(6),
            'adv3'  => (new AdvertService())->getAdvertList(7),
            'adv4'  => (new AdvertService())->getAdvertList(8),
            'adv5'  => (new AdvertService())->getAdvertList(9),
        ];

        //首页充值广告
        $chargeActive = Db::name('charge_active')
            ->where('status', 1)
            ->where('start_time', '<=', time())
            ->where('end_time', '>=', time())
            ->find() ?: [];

        $this->response([
            'swipeList'         => $swipeList,
            'publicNotice'      => $publicNotice,
            'advList'           => $advList,
            'chargeActive'      => $chargeActive
        ]);

    }









}
